package petertel.pbx.conf.extensions;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import petertel.pbx.utils.ConfigItem;

public class Extension {

	private List<Statement> statements = new ArrayList<Statement>();

	private String name;

	public String getName() {
		return name;
	}

	public Iterator<Statement> getStatements() {
		return statements.iterator();
	}

	public BuildingStatus build(ConfigItem config) {
		Statement stmt = new Statement(config);
		if (stmt.getType() == StatementType.EXTEN) {
			String extName = stmt.getName();
			if (name == null) {
				name = extName;
				stmt.setDisplayName(true);
			} else if (!extName.equals(name)) {
				return BuildingStatus.rejected;
			} else {
				;
			}
		} else if (stmt.getType() == StatementType.SAME) {
			;
		} else if (stmt.getType() == StatementType.IGNOREPAT) {
			return BuildingStatus.ignored;
		} else if (stmt.getType() == StatementType.INCLUDE) {
			return BuildingStatus.ignored;
		} else if (stmt.getType() == StatementType.SWITCH) {
			return BuildingStatus.ignored;
		} else {
			throw new RuntimeException("Unknown type: " + stmt.getType());
		}
		statements.add(stmt);
		return BuildingStatus.accepted;
	}

}
